package com.ruoyi.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ruoyi.domain.Administration;
import com.ruoyi.domain.AdsRecoverStation;
import com.ruoyi.mapper.AdministrationMapper;
import com.ruoyi.service.IAdministrationService;
import com.ruoyi.domain.Kind;
import com.ruoyi.service.IAdsRecoverStationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

/**
 * 审批管理Service业务层处理
 *
 * @author ya
 * @date 2025-01-18
 */
@Service
public class AdministrationServiceImpl extends ServiceImpl<AdministrationMapper,Administration> implements IAdministrationService
{
    @Autowired
    private AdministrationMapper administrationMapper;

    @Autowired
    private IAdsRecoverStationService adsRecoverStationService;



    @Override
    public List<AdsRecoverStation> updateAdsDeletedStatus(Long[] ids) {
        List<AdsRecoverStation> adsRecoverStations = new ArrayList<>();
        for (Long id : ids){
            Administration administration = administrationMapper.selectById(id);
            //回收站数据
            AdsRecoverStation adsRecoverStation = new AdsRecoverStation();
            if (administration != null){
                adsRecoverStation.setValidDate(30);//默认30天
                adsRecoverStation.setAdsId(Math.toIntExact(administration.getId()));
                if (administration.getItem()!=null)
                    adsRecoverStation.setItem(administration.getItem());
                if (administration.getNumber()!=null)
                    adsRecoverStation.setNumber(administration.getNumber());
                if (administration.getFilm()!=null)
                    adsRecoverStation.setFilm(administration.getFilm());
                if (administration.getDate()!=null)
                    adsRecoverStation.setDate(administration.getDate());
                if (administration.getState()!=null)
                    adsRecoverStation.setState(administration.getState());
                if (administration.getWriter()!=null)
                    adsRecoverStation.setWriter(administration.getWriter());
                if (administration.getPubdate()!=null)
                    adsRecoverStation.setPubdate(administration.getPubdate());
                if (administration.getOrigin()!=null)
                    adsRecoverStation.setOrigin(administration.getOrigin());
                if (administration.getClick()!=null)
                    adsRecoverStation.setClick(administration.getClick());
                if (administration.getFilePath()!=null)
                    adsRecoverStation.setFilePath(administration.getFilePath());
                if (administration.getAppval()!=null)
                    adsRecoverStation.setAppval(administration.getAppval());
                if (administration.getKind()!=null)
                    adsRecoverStation.setKind(administration.getKind());
                if (administration.getRemark()!=null)
                    adsRecoverStation.setRemark(administration.getRemark());
                if (administration.getCreateTime()!=null)
                    adsRecoverStation.setCreateTime(administration.getCreateTime());
                if (administration.getUpdateTime()!=null)
                    adsRecoverStation.setUpdateTime(administration.getUpdateTime());
                if (administration.getCreateBy()!=null)
                    adsRecoverStation.setCreateBy(administration.getCreateBy());
                if (administration.getUpdateBy()!=null)
                    adsRecoverStation.setUpdateBy(administration.getUpdateBy());
            }
            adsRecoverStations.add(adsRecoverStation);
            System.out.println("回收站数据111："+adsRecoverStation);
            adsRecoverStationService.save(adsRecoverStation);

        }
        return adsRecoverStations;
    }

    @Override
    public List<Kind> selectKindList() {
        return administrationMapper.selectKindList();
    }



    /**
     * 查询审批管理
     *
     * @param id 审批管理主键
     * @return 审批管理
     */
    @Override
    public Administration selectAdministrationById(String id)
    {
        return administrationMapper.selectAdministrationById(id);
    }
    /**
     * 查询审批管理
     *
     * @param kind 审批管理种类
     * @return 审批管理
     */
    @Override
    public List<Administration> selectAdministrationByKind(String kind)
    {
        return administrationMapper.selectAdministrationByKind(kind);
    }

    /**
     * 查询审批管理列表
     *
     * @param administration 审批管理
     * @return 审批管理
     */
    @Override
    public List<Administration> selectAdministrationList(Administration administration)
    {
        return administrationMapper.selectAdministrationList(administration);
    }

    /**
     * 新增审批管理
     *
     * @param administration 审批管理
     * @return 结果
     */
    @Override
    public int insertAdministration(Administration administration)
    {
        return administrationMapper.insertAdministration(administration);
    }

    /**
     * 修改审批管理
     *
     * @param administration 审批管理
     * @return 结果
     */
    @Override
    public int updateAdministration(Administration administration)
    {
        return administrationMapper.updateAdministration(administration);
    }

    /**
     * 批量删除审批管理
     *
     * @param ids 需要删除的审批管理主键
     * @return 结果
     */
    @Override
    public int deleteAdministrationByIds(String[] ids)
    {
        return administrationMapper.deleteAdministrationByIds(ids);
    }

    /**
     * 删除审批管理信息
     *
     * @param id 审批管理主键
     * @return 结果
     */
    @Override
    public int deleteAdministrationById(String id)
    {
        return administrationMapper.deleteAdministrationById(id);
    }
}
